import { action, observable, computed } from 'mobx';
import * as Api from '../../api/plan/planViewApi';
import { ListViewPage, Browser, BrowserHrm } from 'weaver-mobile-page';
import { Tools,Bubble } from 'weaver-mobile';

const getLabel = Tools.getLabel;

export default class PlanResultStore {

    @observable list = new ListViewPage.Store({ route: '/planHome/planResult' });
    @observable subBrowser = new Browser.Store({ route: '/planHome/planResult/condition/subBrowser' });
    @observable deptBrowser = new Browser.Store({ route: '/planHome/planResult/condition/deptBrowser' });
    @observable browserHrm = new BrowserHrm.Store({ route: '/planHome/planResult/condition/browserHrm' });
    @observable subBrowserValue = [];
    @observable deptBrowserValue = [];
    @observable browserHrmValue = [];
    @observable tabs = [{"isSearch":false,"key":"2","name": getLabel(18770, "按组织结构"),"selected":false,"showOrder":0}
    ,{"dataParams":{"list":"1"},"isSearch":true,"key":"1","name":getLabel(130619, '按列表'),"selected":false,"showOrder":0}];

    @observable stabList = []; 

    @observable weekList = []
    @observable weekText = ""
    @observable totalWeek = 54

    @computed get type() {
        let value = '';
        this.stabList.map(item => {
            if (item.key == this.queryParams.type1) {
                value = item.title;
            }
        })
        return value;
    }

    @observable queryParams = { //查询条件
        year: new Date().getFullYear(),//年份
        dateType: "1", //类型
        dateValue: new Date().getMonth(),  //值
        status: "", //状态
        humId: "", //人员
        planName: "",//名称
        includeSubType: "3", //是否包含分部，默认含子分部
        subId: "", //分部
        includeDepType: "3", //是否包含部门，默认含子部门
        depId: "", //部门
    };
    @observable planTypeData = [
        { key: '1', title: getLabel(20617,'月报'),showname:getLabel(20617,'月报') },
        { key: '2', title: getLabel(20619,'周报') ,showname:getLabel(20619,'周报')},
    ]
    @observable statusData = [
        { key: '0', showname: getLabel('220', '草稿') },
        { key: '1', showname:  getLabel('19134', '审批中') },
        { key: '3', showname: getLabel('23774', '已完成') },
        { key: '-1', showname: getLabel(25740, '其他') },
    ];
    @observable statusValue = {
        "-1": getLabel('508873', '无数据'),
        "0": getLabel('220', '草稿'),
        "1": getLabel('19134', '审批中'),
        "2": getLabel('236', '退回'),
        "3": getLabel('23774', '已完成'),
        "4": getLabel('1979', '未开始'),
        "6": getLabel('382750', '已过期'),
        "7": getLabel('508873', '无数据'),
    }

    @observable includesubData = [
        { key: "3", showname: getLabel('508780', '含子分部') },
        { key: "1", showname: getLabel('18919', '仅本分部') },
        { key: "2", showname: getLabel('18920', '仅子分部') },
    ];
    @observable includedeptData = [
        { key: "3", showname: getLabel('508784', '含子部门') },
        { key: "1", showname: getLabel('18916', '仅本部门') },
        { key: "2", showname: getLabel('18917', '仅子部门') },
    ];


    @action("初始化操作")
    doInit = () => {
        // this.initData();
        this.getTableDatas()
    }

    @action("搜索条件改变")
    onSearchChange = (params) => {
        for (let key in params) {
            this.queryParams[key] = params[key];
        }
    }

    @action("重置条件")
    resetCondition = () => {
        this.queryParams = { //查询条件
            year:new Date().getFullYear(),//年份
            dateType: "1", //类型
            dateValue: new Date().getMonth(),  //月份或季度
            status: "", //状态
            humId: "", //人员
            planName: "",//名称
            includeSubType: "3", //是否包含分部，默认含子分部
            subId: "", //分部
            includeDepType: "3", //是否包含部门，默认含子部门
            depId: "", //部门
            planName:'',
        };
        this.subBrowserValue = [];
        this.deptBrowserValue = [];
        this.browserHrmValue = [];
    }

    @action
    setState = (params = {}) => {
        Object.keys(params).forEach((key) => {
            this[key] = params[key];
        });
    }

    @action("获取考核周期数据")
    initData = () => {
        this.getTableDatas();
    };

    @action("渲染table数据")
    getTableDatas = () => {
        this.list.clearData();
        if(this.queryParams.dateType == 1 && this.queryParams.dateValue==0){
            this.queryParams.dateValue=12
            if(this.queryParams.year == new Date().getFullYear()){
                this.queryParams.year -=1
            }
        }
        Api.planResult(this.queryParams).then(action(res => {
            if (res.api_status) {
                const { datas: dataKey } = res;
                this.list.getData({ dataKey });
            } else {
                Bubble.error(getLabel('508818', '接口调用失败！'), 3,null,null,null,false);
            }
        }));
    };
    //getweek
    @action getWeek = (params = {}) => {
        // Toast.loading('loading',0)
        return Api.getWeek(params).then(res => {
            this.weekList = res.datas
            this.weekText = res.currentdates
            this.totalWeek = res.totalWeek
            return res
        });
    }

}